package com.hmall.common.config;

import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//实现WebMvcConfigurer接口，重写addInterceptors方法，添加自定义拦截器
@Configuration
@ConditionalOnClass(DispatcherServlet.class)//判断是否引入了SpringMVC的依赖,网关没有mvc依赖所以不会引入
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器,默认拦截所以路径，如果需要则可以自己配置拦截路径
        registry.addInterceptor(new UserInfoInterceptor());
    }
}
